#ifndef renderer_directx9_h__
#define renderer_directx9_h__
#include "graphics/irenderer.h"
#include <d3d9.h>

namespace gecko
{

// DirectX 9 implementation of renderer
class Renderer_DirectX9 : public IRenderer
{
	//DEFINE_NEWDELETE(Renderer_DirectX9)
public:
    // Clear the renderer
    void Clear();

    // Set the clear colour
    void SetClearColour(const Colour& colour);

    // Start rendering the scene
    bool BeginScene();

    // End rendering the scene
    bool EndScene();

    // Swap buffers and display the scene
    bool Present();

    // Cleanup after shutdown
    bool Destroy();

	// Initialise the renderer
	bool Initialise(int width, int height, int bpp, bool fullscreen);

	// setup camera
	bool SetCamera(const Vector3f& from, const Vector3f& at, const Vector3f& up, float fov);
	
	// Set an orthographic (2D) projection matrix
	bool SetOrthoProjection(int width, int height);

	// Set a perspective projection matrix
	bool SetPerspectiveProjection(float fov, int width, int height, double nearClip, double farClip);

	// Create a vertex buffer.
	IVertexBuffer* CreateVertexBuffer(unsigned int vertexCount, bool dynamic);

	// Create an index buffer.
	IIndexBuffer* CreateIndexBuffer(unsigned int indexCount, bool dynamic);

	// Create a shader from a file
	IShader* CreateShader(const char* filename, unsigned int numParameters);

	// set the global rendermode
	void SetRenderMode(eRendermode renderMode);

	LPDIRECT3DDEVICE9 GetD3DDevice();

private:
	struct SDisplayMode
	{
		int m_width;
		int m_height;
	};

	bool EnumerateDisplayModes();
	void GeneratePresentParameters(int width, int height, bool fullscreen);

	LPDIRECT3D9 m_pD3D;
	LPDIRECT3DDEVICE9 m_pd3dDevice;
	D3DCOLOR m_clearColour;
	D3DPRESENT_PARAMETERS m_d3dpp;
	int m_iViewportWidth;
	int m_iViewportHeight;
	int m_width;
	int m_height;
	SDisplayMode m_displayModes[64];

	// camera
	Vector3f m_cameraFrom;
	Vector3f m_cameraAt;
	Vector3f m_cameraUp;
	float m_cameraFOV;
};

}// namespace gecko

#endif // renderer_directx9_h__